from sanic import response

from mysql_.Orm_DB import *
from view.register import bp1
from my_jinja2.my_jinja2 import template


@bp1.route('/login', methods=['GET', 'POST'])
async def login(request):
    username = request.form.get('user')
    password = request.form.get('pwd')

    print(username)
    print(password)

    if db_query(username) == False:
        dict = {'key': 'userfail'}
        return response.json(dict)
    else:
        password_ = db_query(username)
        if password == password_['password']:
            dict = {'key':'success','message':password_}
            return response.json(dict)
        else:
            dict = {'key': 'fail'}
            return response.json(dict)



# @bp1.route('/login', methods=['GET', 'POST'])
# async def login(request):
#     if request.method == 'POST':
#
#         if request.form.get('login') == '登陆':
#             username = request.form.get('username')
#             password = request.form.get('password')
#             json({'账号：': username})
#             json({'密码：': password})
#
#             checkDB = data.server_rdout(username, password)
#             if checkDB:
#                 print('success!')
#             else:
#                 print('fail!')
#
#         if request.form.get('submit') == '去注册':
#             return redirect('/')
#
#         if request.form.get('find') == '找回密码':
#             return redirect('/findback')
#
#         if request.form.get('reset_pw') == '修改密码':
#             return redirect('/reset_pw')
#
#     return template('login.html')

